from typing import List, Optional

from pydantic import Field, BaseModel
from datetime import datetime

from apps.utils.enumerate import StateEnum


class BaseUserSchema(BaseModel):
    account: str = Field(description='账号', title='account')
    password: str = Field(description='密码', title='password', min_length=6)
    mobile: str = Field(description="手机号", title="mobile")


class CreateUserSchema(BaseUserSchema):
    __doc__ = "创建用户模式"
    is_admin: bool = Field(False, description="是否是管理员", title="is_admin")


class UpdateUserSchema(BaseModel):
    __doc__ = "更新用户模式"
    account: str = Field(None, description='账号', title='account')
    password: str = Field(None, description='密码', title='password')
    mobile: str = Field(None, description="手机号", title="mobile")
    is_admin: bool = Field(None, description="是否是管理员", title="password")
    state: StateEnum = Field(None, description="允许登录的权限,1:允许,2:禁用", title="state")
    update_date: datetime = Field(None, description="更新时间", title="update_date")


class UserSchema(BaseUserSchema):
    __doc__ = "单个用户所有信息"
    id: Optional[int] = Field(description="id", title="id")
    create_date: Optional[datetime] = Field(description="创建时间", title="create_time")
    state: StateEnum = Field(StateEnum.allow, description="允许登录的权限,1:允许,2:禁用", title="state")
    is_admin: Optional[bool] = Field(None, description="是否是管理员", title="password")


class GetUserListSchema(BaseModel):
    __doc__ = "获取用户分页列表"
    total: int
    result: List[UserSchema]
